package com.bosintek.wordtest.gui;

import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;

import com.bosintek.wordtest.Bank;
import com.bosintek.wordtest.R;
import com.bosintek.wordtest.util.ObjectsManager;

public class BankItemWrapper implements OnClickListener {

	private TextView name = null;
	private TextView info = null;
	private Button btnLoad = null;
	private Bank bank = null;
	private View row = null;

	public BankItemWrapper(View row) {
		this.row = row; // The View object that represents a single row
	}

	public void populateFrom(Bank b) { // Associate to the item components the
										// value from the menu bean
		bank = b;
		getName().setText(b.getName());
		getInfo().setText(
				"#Sets: " + b.getwSets().size() + "" + b.getDescription());
		getButton().setOnClickListener(this);
	}

	TextView getName() {
		if (name == null) {
			name = (TextView) row.findViewById(R.id.txtBankName);
		}
		return (name);
	}

	TextView getInfo() {
		if (info == null) {
			info = (TextView) row.findViewById(R.id.txtBankInfo);
		}
		return (info);
	}

	Button getButton() {
		if (btnLoad == null) {
			btnLoad = (Button) row.findViewById(R.id.btnLoadBank);
		}
		return (btnLoad);
	}

	@Override
	public void onClick(View arg0) {
		// TODO Auto-generated method stub
		ObjectsManager.setMustReload(true);
		if (bank != null) {
			ObjectsManager.setCurrentBank(bank);
			ObjectsManager.setMustReload(true);
		} else {
			// The bank couldn't be loaded.
		}
	}

}